package client.net.handler;

import client.Client;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
import shared.net.protocol.PacketCreator;

/**
 * This class handles any pings that the client receives.
 *
 * @author Vincent Tsuei
 * @author Andrew Gratta
 * @version 2012-11-21
 */
public class PingHandler implements ClientPacketHandler {

    @Override
    public int processPacket(Client client, ByteBuffer packet) {
        if (client == null || packet == null)
        {
            return -1;
        }
        int pingId = packet.getInt();
        Logger.getLogger(PingHandler.class.getName()).log(Level.FINER, "Ping received with ID: {0}", pingId);
        client.queuePacketForWriteAsync(PacketCreator.PING.getPongPacket(pingId));
        return 0;
    }
}
